<!-- 台区 -->
<template>
  <div>
    <el-dialog v-bind="dialogProps" :before-close="handleClose" :close-on-click-modal="false"
               :destroy-on-close="true" v-dialogDrag append-to-body>

      <el-form :model="ruleForm" ref="ruleForm" label-width="120px" class="demo-ruleForm" :size="size">
        <el-row :gutter="16" justify="start">
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="设备名称:" prop="sbmc">
              <el-input v-model="ruleForm.sbmc" clearable placeholder="请选择设备名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="出厂编码:" prop="ccbm">
              <el-input v-model="ruleForm.ccbm" clearable placeholder="请选择设备编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="设备类型:" prop="sblxbm">
              <el-select v-model="ruleForm.sblxbm" placeholder="请选择设备状态" clearable style="width: 100%">
                <el-option v-for="item in djztOptions" :key="item.value" :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item style="float:right">
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <el-button style="margin-left: 10px" @click="handleReset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <div style="height:2px;background:#009688;margin-bottom: 5px;"></div>
        <vxe-table border stripe ref="table1" height="400" :column-config="{ resizable: true }" :size="size"
                   :row-config="{ isHover: true }" @radio-change="radioChangeEvent"
                   :radio-config="{ checkMethod: checkRadioMethod, highlight: true }"
                   :checkbox-config="{ highlight: true }"
                   :data="list1.data" :loading="loading">
          <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
          <vxe-column field="gldwmc" title="单位" align="center" minWidth="150"></vxe-column>
          <vxe-column field="sbmc" title="设备名称" align="center" minWidth="150"></vxe-column>
          <vxe-column field="ccbm" title="出厂编码" align="center" minWidth="200">
            <template v-slot="{ row }">
              <span style="color:#0000FF;cursor: pointer;" @click="handleShow(row)">{{ row.ccbm }}</span>
            </template>
          </vxe-column>
          <vxe-column field="sblxmc" title="设备类型" align="center" minWidth="150"></vxe-column>
          <vxe-column field="pt" title="PT" align="center" minWidth="70"></vxe-column>
          <vxe-column field="ct" title="CT" align="center" minWidth="70"></vxe-column>
          <vxe-column field="sbztmc" title="设备状态" align="center" minWidth="150"></vxe-column>
          <vxe-column field="sskfmc" title="所属库房" align="center" minWidth="150"></vxe-column>
          <vxe-column field="sbgg" title="规格" align="center" minWidth="150"></vxe-column>
          <vxe-column field="xh" title="型号" align="center" minWidth="150"></vxe-column>
          <vxe-column field="yxztmc" title="运行状态" align="center" minWidth="100"></vxe-column>
        </vxe-table>
        <vxe-pager perfect size="mini" :current-page="list1.pageNo" :page-size="list1.pageSize"
                   :page-sizes="list1.pageSizes" :total="list1.total"
                   :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                   @page-change="handlePageChange1">
        </vxe-pager>
      </el-row>
      <span slot="footer" class="dialog-footer">
                <el-button @click="handleCancel()" :size="size" icon="fa fa-minus-square-o">关闭</el-button>
            </span>
    </el-dialog>
    <equipmentMaintenanceForm ref="equipmentMaintenanceForm"></equipmentMaintenanceForm>
  </div>
</template>
<script>
import {accountQueryApi} from '@/api/equip/accountQueryApi.js'
import {godownEntryApi} from "@/api/equip/godownEntryApi";
import equipmentMaintenanceForm from './equipmentMaintenanceForm.vue'

export default {
  components: {equipmentMaintenanceForm},
  data() {
    return {
      selectRow: null,
      selectRow1: null,
      size: "medium",
      ruleForm: {
        sbmc: '',
        ccbm: '',
        sblxbm: ''
      },
      dialogProps: {
        visible: false,
        title: "出库设备详情",
        width: "80%",
        top: "10px",
      },
      djztOptions: [],
      overheadLine: false,

      list1: {
        data: [],
        pageNo: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100],
        total: 0
      },
      loading: false,
      row: {}
    };
  },
  methods: {
    radioChangeEvent() {

    },
    checkRadioMethod() {

    },
    showDialog(isEdit, row, isDisabled) {
      console.log(isEdit, row, isDisabled)
      this.dialogProps.visible = true
      this.row = row
      this.fetchdjztOptions()
      this.ruleForm = {
        sbmc: '',
        ccbm: '',
        sblxbm: ''
      }
      let queryParams = {
        column: '',
        entity: {
          id: row.id,
          sbmc: this.ruleForm.sbmc, //设备名称//
          ccbm: this.ruleForm.ccbm, //规格//
          sblxbm: this.ruleForm.sblxbm, //运行状态  10-未投运
        },
        order: '',
        pageNo: 1,
        pageSize: 10,
        paramsMap: {}
      }
      godownEntryApi.getDjEquipList(queryParams).then(res => {
        this.list1 = {
          data: res.data.records,
          pageNo: res.data.current,
          pageSize: res.data.size,
          pageSizes: [10, 20, 50, 100],
          total: res.data.total
        }
      })
    },
    fetchdjztOptions() {
      accountQueryApi.queryDictDatasb('1000').then(res => {
        // if (res.code === '200') {
        let optionList = [
          {label: '请选择', value: ''}
        ]
        res.data.forEach((item) => {
          optionList.push({label: item.name, value: item.id})
        })
        this.djztOptions = optionList
      })
    },
    //查询
    handleSearch() {
      let queryParams = {
        column: '',
        entity: {
          id: this.row.id,
          sbmc: this.ruleForm.sbmc, //设备名称//
          ccbm: this.ruleForm.ccbm, //规格//
          sblxbm: this.ruleForm.sblxbm, //运行状态  10-未投运
        },
        order: '',
        pageNo: 1,
        pageSize: 10,
        paramsMap: {}
      }
      godownEntryApi.getDjEquipList(queryParams).then(res => {
        this.list1 = {
          data: res.data.records,
          pageNo: res.data.current,
          pageSize: res.data.size,
          pageSizes: [10, 20, 50, 100],
          total: res.data.total
        }
      })
    },
    //重置
    handleReset() {
      this.ruleForm = {
        sbmc: '',
        ccbm: '',
        sblxbm: ''
      }
      let queryParams = {
        column: '',
        entity: {
          id: this.row.id,
          sbmc: this.ruleForm.sbmc, //设备名称//
          ccbm: this.ruleForm.ccbm, //规格//
          sblxbm: this.ruleForm.sblxbm, //运行状态  10-未投运
        },
        order: '',
        pageNo: 1,
        pageSize: 10,
        paramsMap: {}
      }
      godownEntryApi.getDjEquipList(queryParams).then(res => {
        this.list1 = {
          data: res.data.records,
          pageNo: res.data.current,
          pageSize: res.data.size,
          pageSizes: [10, 20, 50, 100],
          total: res.data.total
        }
      })
    },
    //分页查询
    handlePageChange1({currentPage, pageSize}) {
      this.loading = true
      this.list1.pageNo = currentPage;
      this.list1.pageSize = pageSize;
      this.handleSearch()
    },
    handlePageChange2({currentPage, pageSize}) {
      this.loading = true
      this.list2.pageNo = currentPage;
      this.list2.pageSize = pageSize;
      this.handleSearch()
    },
    handleShow(val) {
      this.$refs.equipmentMaintenanceForm.showDialog(false, val, true)
    },
    //取消
    handleCancel() {
      this.$refs.ruleForm.resetFields()
      this.dialogProps.visible = false;
    },
    handleClose(done) {
      // this.$confirm("确认关闭？")
      //     .then((_) => {
      this.handleCancel()
      this.dialogProps.visible = false;
      // })
      // .catch((_) => { });
    },
  },
};
// 创建一个简单的超链接渲染

</script>
<style>
.el-dialog__footer {
  width: 100%;
  border-top: 1px solid #e8e8e8;
}
</style>
